package com.yunfei.commonbase.token;

import com.yunfei.commonbase.base64.Base64Utils;
import com.yunfei.commonbase.exception.DataException;

import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Date;

public class TokenUtils {
    /**
     * 获取token
     * @param id
     * @param username
     * @param passowrd
     * @param expDay
     * @return
     */
    public String getToken(int id,String username,String passowrd,int expDay) throws DataException, UnsupportedEncodingException {
        StringBuilder stringBuilder =new StringBuilder();
        stringBuilder.append(System.currentTimeMillis()).append("`").append(id).append("`").append(username).append("`").append(passowrd).append("`").append(expDay);
        String str= Base64.getEncoder().encodeToString(stringBuilder.toString().getBytes("utf-8"));
        String base64decoderString = Base64Utils.getBase64encoderString(str);
        return base64decoderString;
    }

    public static void main(String[] args) throws UnsupportedEncodingException, DataException {
        TokenUtils tokenUtils = new TokenUtils();
        String token = tokenUtils.getToken(1,"13855201101","123456",1);
        System.out.println(token);
    }
}
